import keyManager
import fileProc
import sys

if __name__ == "__main__":
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("-p","--put",action="store_true", dest = "put",default=False,
                      help="Put the file")
    parser.add_option("-g","--get",action="store_true", dest = "get",default=False,
                      help="get the file")
    parser.add_option("-f","--file",dest="filename",default=None,
                     help="filename to put or get")
    parser.add_option("-k","--key",dest="aesKey",default=None,
                      help="Key to ne used with AES to encrypt RSA keys")
    (options, args) = parser.parse_args()
    if options.aesKey == None:
        print "aesKey is required"
        sys.exit(1)
    if not options.get and not options.put:
        print "Either put or get option is required"
        sys.exit(1)
    manager = keyManager.KeyManager(options.aesKey)
    key = manager.getKeys();
    proc = fileProc.FileProc(key)
    if options.get:
        if options.filename == None:
            proc.list()
        else:
            proc.get(options.filename)
    if options.put:
        if options.filename == None:
            print "filename required to put"
            sys.exit(1)
        else:
            proc.put(options.filename)